{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Two Loop TDEM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from geoscilabs.base import widgetify\n",
    "import geoscilabs.em.InductionLoop as IND\n",
    "from ipywidgets import interact, FloatSlider, FloatText"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## App Parameter Descriptions\n",
    "\n",
    "<img style=\"float: right; width: 500px\" src=\"https://github.com/geoscixyz/geosci-labs/blob/master/images/em/InductionLoop.png?raw=true\">\n",
    "\n",
    "Below are the adjustable parameters for widgets within this notebook:\n",
    "\n",
    "* $I_p$: Transmitter current amplitude [A]\n",
    "* $a_{Tx}$: Transmitter loop radius [m]\n",
    "* $a_{Rx}$: Receiver loop radius [m]\n",
    "* $x_{Rx}$: Receiver x position [m]\n",
    "* $z_{Rx}$: Receiver z position [m]\n",
    "* $\\theta$: Receiver normal vector relative to vertical [degrees]\n",
    "* $R$: Resistance of receiver loop [$\\Omega$]\n",
    "* $L$: Inductance of receiver loop [H]\n",
    "* $f$: Specific frequency [Hz]\n",
    "* $t$: Specific time [s]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Background Theory: Induced Currents due to a Step-Off Primary Signal\n",
    "\n",
    "Consider the case in the image below, where a circular loop of wire ($Tx$) caries a time-varying current $I_p (t)$. According to the Biot-Savart law, this produces a time-varying primary magnetic field. The time-varying nature of the corresponding magnetic flux which passes through the receiver coil ($Rx$) generates an induced secondary current $I_s (t)$, which depends on the coil's resistance ($R$) and inductance ($L$). Here, we will provided final analytic results associated with the app below. A full derivation can be found at the bottom of the page.\n",
    "\n",
    "For a step-off primary current of the form $I_p (t) = I_0 u(-t)$, the secondary current carried by ($Rx$) is given by:\n",
    "\n",
    "\\begin{equation}\n",
    "I_s (t) = \\frac{I_0 A \\beta_n}{L} \\, \\textrm{e}^{-Rt/L} \\, u(t)\n",
    "\\end{equation}\n",
    "\n",
    "where $A$ is the area of $Rx$, $\\beta$ contains the geometric information pertaining to the problem and $u(t)$ is the unit-step function."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6fb5a2ec7c47411c963a7085d4b5d052",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "MyApp(children=(FloatSlider(value=1.0, continuous_update=False, description='$I_0$', min=0.01, step=1.0), Floa…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# RUN TRANSIENT WIDGET\n",
    "widgetify(IND.fcn_TDEM_Widget,I=FloatSlider(min=0.01, max=100., value=1., step=1., continuous_update=False, description = \"$I_0$\"),\\\n",
    "                        a1=FloatSlider(min=1., max=20., value=10., step=1., continuous_update=False, description = \"$a_{Tx}$\"),\\\n",
    "                        a2=FloatSlider(min=1., max=20., value=5., step=1., continuous_update=False, description = \"$a_{Rx}$\"),\\\n",
    "                        xRx=FloatSlider(min=-15., max=15., value=0., step=1., continuous_update=False, description = \"$x_{Rx}$\"),\\\n",
    "                        zRx=FloatSlider(min=-15., max=15., value=-8., step=1., continuous_update=False, description = \"$z_{Rx}$\"),\\\n",
    "                        azm=FloatSlider(min=-90., max=90., value=0., step=10., continuous_update=False, description = \"$\\\\theta$\"),\\\n",
    "                        logR=FloatSlider(min=0, max=6, value=2, step=1., continuous_update=False, description = \"$log_{10}(R)$\"),\\\n",
    "                        logL=FloatSlider(min=-7, max=-2, value=-2, step=1., continuous_update=False, description = \"$log_{10}(L)$\"),\\\n",
    "                        logt=FloatSlider(min=-6, max=-2, value=-4, step=1., continuous_update=False, description = \"$log_{10}(t)$\"))\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Supporting Derivation for the Transient Response\n",
    "\n",
    "Consider a transmitter loop which carries a primary current of the form:\n",
    "\\begin{equation}\n",
    "I_p(t) = I_0 \\, u(-t)\n",
    "\\end{equation}\n",
    "where $u(t)$ is the unit-step function. According to the Biot-Savart law, this results in a primary magnetic field:\n",
    "\\begin{equation}\n",
    "\\mathbf{B_p} (\\mathbf{r},t) =  \\boldsymbol{\\beta} \\, I_0 \\, t(-t)  \\;\\;\\;\\; \\textrm{where} \\;\\;\\;\\;\\; \\boldsymbol{\\beta} = \\frac{\\mu_0}{4 \\pi} \\int_C \\frac{d \\mathbf{l} \\times \\mathbf{r'}}{|\\mathbf{r'}|^2}\n",
    "\\end{equation}\n",
    "where $\\boldsymbol{\\beta}$ contains the problem geometry. Assume the magnetic field is homogeneous through the receiver loop. The primary field generates an EMF within the receiver loop equal to:\n",
    "\\begin{equation}\n",
    "EMF = - i\\omega \\Phi \\;\\;\\;\\;\\; \\textrm{where} \\;\\;\\;\\;\\; \\Phi =  A \\beta_n I_0 \\, u(-t)\n",
    "\\end{equation}\n",
    "where $A$ is the area of the receiver loop and $\\beta_n$ is the component of $\\boldsymbol{\\beta}$ along $\\hat n$. The EMF induces a secondary current $I_s$ within the receiver loop. Instead of solving the problem directly in the time-domain, we will apply the inverse Fourier transform to frequency-domain solutions. The secondary current induced in the receiver loop can be obtained through a convolution:\n",
    "\\begin{equation}\n",
    "I_s (t) = h(t) \\otimes u(-t)\n",
    "\\end{equation}\n",
    "where $h(t)$ is the inverse Fourier transform of the harmonic solution:\n",
    "\\begin{equation}\n",
    "h(t) = \\mathbb{F}^{-1} \\big [ I_s (\\omega) \\big ] = - \\frac{I_0 A \\beta_n}{L} \\frac{d}{dt} \\bigg [ \\textrm{e}^{-Rt/L} \\, u(t) \\bigg ]\n",
    "\\end{equation}\n",
    "Thus the secondary current induced in the receiver loop is given by:\n",
    "\\begin{equation}\n",
    "I_s (t) = \\frac{I_0 A \\beta_n}{L} \\, \\textrm{e}^{-Rt/L} \\, u(t)\n",
    "\\end{equation}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  },
  "widgets": {
   "state": {
    "34c44d97738a4395ab9dc42a7785e251": {
     "views": [
      {
       "cell_index": 3
      }
     ]
    }
   },
   "version": "1.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
